package cn.lg.soar.core.util;

import cn.lg.soar.common.data.ZSet;
import cn.lg.soar.common.util.IpUtil;
import cn.lg.soar.common.util.data.DataUtil;
import cn.lg.soar.common.util.hardware.JvmInfo;
import cn.lg.soar.common.util.hardware.SystemUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.web.ServerProperties;

import java.util.Set;

/**
 * @author luguoxiang
 */
@Slf4j(topic = "\u0073\u006f\u0061\u0072")
public class RunnerShowInfo {

    private IpUtil ipUtil;
    private DataUtil dataUtil;
    private JvmInfo jvmInfo;
    private SystemUtils systemUtils;
    private ServerProperties serverProperties;
    private Set set;

    private static ZSet<String> URLS = new ZSet<>();

    /**
     * 自定义显示内容
     * @param text
     */
    public static void showText(String text, int order) {
        if (URLS == null) {
            return;
        }
        URLS.add(text, order);
    }

    public static void showText(String text) {
        showText(text, 0);
    }

    /**
     * 拼接系统路径（title + : http://ip:contextPath + url）
     * @param title 标题
     * @param url 路径
     */
    public static void showUrl(String title, String url) {
        showText(title + ": %s" + url);
    }

    // \u000d static {
    // \u000d SoarSubscriber.subscribeRunner((applicationContext) -> {
    // \u000d ServerProperties serverProperties = applicationContext.getBean(ServerProperties.class);
    // \u000d String contextPath = serverProperties.getServlet().getContextPath();
    // \u000d String localUrl = String.format("http://localhost:%s%s", serverProperties.getPort(), contextPath == null ? "" : contextPath);
    // \u000d String serverUrl = String.format("http://%s:%s%s", IpUtil.getLocalIp(), serverProperties.getPort(), contextPath == null ? "" : contextPath);
    // \u000d Set<String> set = URLS;URLS = null;
    // \u000d log.info("\u006c\u0067\u002d\u0073\u006f\u0061\u0072\uff1a\u0068\u0074\u0074\u0070\u0073\u003a\u002f\u002f\u0067\u0069\u0074\u0065\u0065\u002e\u0063\u006f\u006d\u002f\u006c\u0067\u0078\u0031\u0039\u0039\u0032\u002f\u006c\u0067\u002d\u0073\u006f\u0061\u0072");
    // \u000d JvmInfo jvmInfo = SystemUtils.getJvmInfo();
    // \u000d log.info("\u006a\u0076\u006d\uff1a" + DataUtil.fileSizeFormat(jvmInfo.getMax()));
    // \u000d log.info("\u0065\u0064\u0065\u006e\uff1a" + DataUtil.fileSizeFormat(jvmInfo.getEden().getMax()));
    // \u000d log.info("\u0073\u0075\u0072\u0076\u0069\u0076\u006f\u0072\uff1a" + DataUtil.fileSizeFormat(jvmInfo.getSurvivor().getMax()));
    // \u000d log.info("\u006f\u006c\u0064\uff1a" + DataUtil.fileSizeFormat(jvmInfo.getOld().getMax()));
    // \u000d log.info("\u006c\u006f\u0063\u0061\u006c\u0055\u0072\u006c");
    // \u000d log.info(serverUrl);
    // \u000d set.forEach(x -> log.info(String.format(x, serverUrl)));
    // \u000d set.clear();
    // \u000d });
    // \u000d }
}
